/**
 * wwwen 通讯，数据集合
 */
function winApp(){
    console.log('create winApp===================');
    this.cn='cls_';
    /**增加数**/
    this.clsId=100;
    /**通知集合**/
    this.notification={};
    /**通知分隔符**/
    this.nSeparate="n_sss123_n";


}


winApp.prototype.getConfig=function(){
    console.log('winApp getConfig');
}

/**
 * 获取一个唯一值
 * @returns {number}
 */
winApp.prototype.getClsId=function(){
    this.clsId++;
   // console.log('winApp getClsId',this.clsId);
    return (this.cn+this.clsId);
}
/**
 * 发送通知
 * cmd:String 通知标注 事件字符串
 * data:数据
 */
winApp.prototype.sendNotification=function(cmd,data){
    for(let i in this.notification){
        let _cmd=i.split(this.nSeparate)[0];
        if(cmd==_cmd){
            //console.log("winApp sendNotification 发送通知",i,cmd);
            this.notification[i](data);
        }
    }
}
/**
 *注册通知  事件_标识_classID
 *cmd:String 通知标注
 *clsKey:String 通知对象标注 clsId
 *handler:Function 执行函数
 */
winApp.prototype.bindHandler=function(cmd,clsKey,handler){
    let _cmdKey=cmd+this.nSeparate+clsKey;
    this.notification[_cmdKey]=handler;
    // console.log("winApp bindHandler 注册通知",_cmdKey);
}
/**
 * 取消通知
 * @param clsKey:String 通知对象标注
 * @param cmd:String 事件名称
 */
winApp.prototype.deleteNotification=function(clsKey,cmd){
    if(cmd==null){//取消这个class的全部注册
        for(let i in this.notification){
            let _clsKey=i.split(this.nSeparate)[1];
            if(_clsKey==clsKey){
                this.notification[i]=null;
                delete this.notification[i];
                 console.log("winApp deleteNotification 取消通知",this.notification[i],clsKey,this.notification);
            }
        }
    }else{
        for(let i in this.notification){
            let _cmd=i.split(this.nSeparate)[0];
            let _clsKey=i.split(this.nSeparate)[1];
            if(_clsKey==clsKey && cmd==_cmd){
                 console.log("winApp deleteNotification 取消通知",_clsKey,clsKey,_cmd,cmd);
                this.notification[i]=null;
                delete this.notification[i];
            }
        }
    }

}


export default winApp;
